home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
TUTORIAL
/
1307A.ZIP
/
CHAP16.TXT
< prev
next >
Wrap
Text File
|
1989-01-18
|
7KB
|
176 lines
Chapter 16
COMPLETE EXAMPLE PROGRAMS
WHY THIS CHAPTER?
______________________________________________________________
The intent of this chapter is to give several example programs
that use nearly every capability of Modula-2 as illustrations
of large usable programs. The programs are usable utilities,
but primarily they are intended to illustrate the method of
building up a medium sized program from the various constructs
studied in the earlier chapters. Even though most of these
programs are designed to be run on an IBM-PC or compatible,
the techniques are applicable to any system by changing the
system calls.
The first three programs are the beginning of a hard disk
backup utility. Although it works, it does have a few
limitations that need fixed before it can really be used for
a production backup system. It has never been refined, but
it is included here as an illustration of how to put together
a large program in Modula-2. It can be used as a backup
system if you don't mind the following problems and
limitations.
1. The date and time of the files on the copy are the date
and time that the copies are made, not the original date
on the original files.
2. This system does not copy hidden files.
3. This system does not copy files that are too big to fit
on one floppy disk.
4. The filesize and the room remaining on the disk are
handled using floating point numbers because LONGCARD was
not available when this program was originally written.
There are enough significant digits in the floating point
numbers to allow this, but using the long cardinal type
would be a great improvement.
The interested student may wish to use this as a beginning
point to develop his own hard disk backup system, and learn
a lot about the use of Modula-2 at the same time.
BAKLIST.MOD
______________________________________________________________
This program generates a list of all files along with their
sub-directories. Some files are excluded from the list,
including all three files that comprise the DOS system and the
file generated here, FULLDISK.LST. This is an ASCII file that
16-1
Chapter 16 - Complete Example Programs
can be edited with any text editor to eliminate any files that
you do not wish to back up. It should be noted that the file,
FULLDISK.LST, is created and filled in the root directory of
the default drive.
Select the desired sub-directory that you wish to back up, by
making it the default directory, and all files and sub-
directories, along with all of their respective contents will
be listed in FULLDISK.LST. The resulting list is then used
by BAKCOPY.MOD to actually copy the files to floppy disks.
This program uses a B-tree sorting algorithm using dynamic
allocation and recursive techniques. The B-tree record is
imported from the module named DirHelps.
BAKCOPY.MOD
______________________________________________________________
This program uses FULLDISK.LST to actually copy the files from
the source disk to the target and requests a disk change
whenever the floppy disk fills up. It will not copy a file
larger than that which will fit on one disk, but will give a
message of which files are not copied.
This program makes no provision for copying a file with an
unusual file attribute and simply copies the entire file if
disk space is available. It also does no file lookahead.
When the next file doesn't fit on the target disk, it simply
requests a new disk. A lookahead scheme could allow several
additional smaller files to be copied to a disk when a larger
file will not fit.
BAKRSTR.MOD
______________________________________________________________
This program will read the files from floppy back to the fixed
disk to restore it. It simply copies from whatever directory
they are in to the corresponding directory on the fixed disk,
creating the directory if necessary. This program uses some
of the procedures from the module named DirHelps. This was
done to illustrate reusability of software.
All three of these programs are usable but lack many of the
refinements necessary to make them completely useful. As the
purchaser of this tutorial, you are permitted to use these
source files as the basis for developing your own hard disk
backup program. If you develop them carefully, you will learn
a lot about the use of Modula-2.
16-2
Chapter 16 - Complete Example Programs
GENERAL PURPOSE GLOBAL MODULES
______________________________________________________________
The remainder of the files in this chapter are useful global
modules which you may be able to use in some of your Modula-
2 programs. They are fairly well documented as to their
capabilities and limitations, and since you have the source
code, you are able to customize them to fit your particular
need.
DIRHELPS.DEF DIRHELPS.MOD
______________________________________________________________
This global module contains several useful file handling and
directory manipulation procedures. It is called by the above
three example programs used for backup and restore of a fixed
disk. These routines are available for your use also if you
desire to use them for a file manipulation program. Their
main intent however is that they be a guide for the student
to observe methods used to write library functions.
BITOPS.DEF BITOPS.MOD
______________________________________________________________
This module has four generic bit operations including logical
AND, OR, XOR, and NOT. These are useful procedures that you
can import and use in your programs if you are doing bit
manipulations.
REAL2MON.DEF REAL2MON.MOD
______________________________________________________________
This module has a procedure to output real data to the monitor
in a neat, easy to read format. It is documented in the
header of the source files.
REAL2FIL.DEF REAL2FIL.MOD
______________________________________________________________
This module has several procedures to output real and other
data type to a file using the FileSystem module. The various
procedures are documented in their respective headers.
16-3